#include <stdio.h>
#include <math.h>

#define A 48271
#define M 2147483647
#define Q (M/A)
#define R (M%A)

static unsigned long Seed=1;

unsigned long _random(void)
{	long TmpSeed;
	TmpSeed=A*(Seed%Q)-R*(Seed/Q);
	if(TmpSeed >= 0)
		Seed=TmpSeed;
	else
		Seed=TmpSeed+M;
	
	return Seed;
}


main() {
  int n,*n1;
  long i;
  float *p,*p1;
  FILE *fp;  
  printf("please input a number of formula:");
  scanf("%d",&n);
  p=(float *)malloc((n*(n+1)+1)*sizeof(float));
  if((fp=fopen("dat","wb+"))==0)
    printf("cannot open file\n");
  *p++=(float)n;
  n1=&n;
  fwrite(n1,sizeof(int),1,fp);
  p1=p;
  for(i=0;i<n*(n+1);i++)
    *(p++)=(float)_random();
  fwrite(p1,sizeof(float),n*(n+1),fp);
  printf("It has generated the data\n");
  fclose(fp);
}
